package gold.digger;

import gold.vo.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC563 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {

        int sum = 0;

        public int findTilt(TreeNode root) {
            findTiltRecur(root);
            return sum;
        }

        public int findTiltRecur(TreeNode root) {
            if (null == root) return 0;
            int leftSum = findTiltRecur(root.left);
            int rightSum = findTiltRecur(root.right);
            sum += Math.abs(leftSum - rightSum);
            return root.val + leftSum + rightSum;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC563 an = new LC563();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
